package game.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

import game.helper.Level;
import game.logic.GameControl;
import game.shared.Constants;
import game.shared.Resources;
import game.windows.Button;
import game.windows.Form;

public class ScreenSelectLevel extends AbsScreen{

	private TextureRegion background;
	private Form startLevel;
	public ScreenSelectLevel(GameControl _gameControl) {
		super(_gameControl);
		background = Resources.getTextureRegion(Resources.BG_SELECT_LEVEL);
		startLevel = new Form();
		loadStartLevel();
	}
	
	@Override
	public void update() {
		super.update();
		startLevel.update();
		dispath();
	}
	
	@Override
	public void render(float arg0) {
		sb.begin();
		sb.draw(background, 0, 0);
		startLevel.render(sb);
		sb.end();
	}
	

	private void loadStartLevel() {
		Button btLock = null;
		
		btLock= new Button(Constants.FUNCTION_CODE_LOCK_1, Resources.getTextureRegion(Resources.LOCK_LEVEL), Resources.getTextureRegion(Resources.LOCK_LEVEL));
		btLock.setXY(100, 40);
		startLevel.addControl(btLock);
		
		btLock = new Button(Constants.FUNCTION_CODE_LOCK_2, Resources.getTextureRegion(Resources.LOCK_LEVEL), Resources.getTextureRegion(Resources.LOCK_LEVEL));
		btLock.setXY(360, 60);
		startLevel.addControl(btLock);
		
		btLock = new Button(Constants.FUNCTION_CODE_LOCK_3, Resources.getTextureRegion(Resources.LOCK_LEVEL), Resources.getTextureRegion(Resources.LOCK_LEVEL));
		btLock.setXY(160, 160);
		startLevel.addControl(btLock);
		
		btLock = new Button(Constants.FUNCTION_CODE_LOCK_4, Resources.getTextureRegion(Resources.LOCK_LEVEL), Resources.getTextureRegion(Resources.LOCK_LEVEL));
		btLock.setXY(100, 260);
		startLevel.addControl(btLock);
		
		btLock = new Button(Constants.FUNCTION_CODE_LOCK_5, Resources.getTextureRegion(Resources.LOCK_LEVEL), Resources.getTextureRegion(Resources.LOCK_LEVEL));
		btLock.setXY(360, 260);
		startLevel.addControl(btLock);
	}
	
	private void dispath() {
		switch (Constants.get_RETURN_CODE()) {
		case Constants.FUNCTION_CODE_LOCK_1:
			Level.level = Constants.LEVEL_DEFAULT;
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		case Constants.FUNCTION_CODE_LOCK_2:
			Level.level = 2;
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		case Constants.FUNCTION_CODE_LOCK_3:
			Level.level = 3;
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		case Constants.FUNCTION_CODE_LOCK_4:
			Level.level = 4;
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		case Constants.FUNCTION_CODE_LOCK_5:
			Level.level = 5;
			gameControl.setScreen(Constants.SCREEN_PLAYING);
			break;
		}
	}
}
